#ifndef MAP_LOADER_H
#define MAP_LOADER_H

#include <QFile>
#include <QDebug>
#include <iostream>

#include "../../core/Landscape.h"

class MapLoader{
		public:
				MapLoader();
                static void loadMap(QString filename, Landscape *land, int* mapWidth, int* mapHeight,
                                    int* nbPlayers, int* nbInitRes){
						QFile file(filename);
                        if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
                            return;
						}

                        QString str = file.readAll();

                        *mapWidth = str.left(str.indexOf(" ")).toInt();
                        str.remove(0, str.indexOf(" ") + 1);

                        *mapHeight = str.left(str.indexOf("\n")).toInt();
                        str.remove(0, str.indexOf("\n") + 1);

                        *nbPlayers = str.left(str.indexOf(" ")).toInt();
                        str.remove(0, str.indexOf(" ") + 1);

                        *nbInitRes = str.left(str.indexOf("\n")).toInt();
                        str.remove(0, str.indexOf("\n") + 1);

                        str.remove("\n");

                        int index = 0;
                        std::vector<long> vec;

                        for(int i = 0; i < *mapWidth; i++){
                            vec.clear();

                            for(int j = 0; j < *mapHeight; j++){
                                vec.push_back(str.at(index).toAscii());
                                index++;
                            }

                            land->cases.push_back(vec);
                        }
				}
};

#endif
